home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 289_01.zip / PIECE_CT.C < prev    next >
Text File  |  1993-04-26  |  2KB  |  56 lines

  1. /*-----------------------------------------------------------------------------
  2. Count the number of pieces of a given type or types.
  3.  
  4. Revision History
  5. ----------------
  6. Gary Culp   7 Jan 1989     Initial version
  7.  
  8. -----------------------------------------------------------------------------*/
  9. #include "othello.h"
  10.  
  11. /*
  12. Function to count the number of pieces of a particular type or types.
  13.  
  14. Returns:
  15.    count of matching pieces
  16.  
  17. Does not calculate the correct value for OFF_BOARD pieces.
  18. */
  19. int
  20. piece_count(struct board_struct *board_ptr, unsigned char piece_type)
  21. {
  22.    register unsigned char *p;
  23.    register unsigned char *stop;
  24.    int count;
  25.  
  26.    count = 0;
  27.    stop =  &board_ptr->board[8][9];
  28.    for (p = &board_ptr->board[1][1]; p < stop; p++) {
  29.       if (*p & piece_type) {
  30.          count++;
  31.       }
  32.    }
  33.    return (count);
  34. }
  35.  
  36. /*
  37. Function to determine whether each player has a move on a given board.
  38.  
  39. Returns:
  40.    The US_PIECE bit is set iff the board contains a move for the computer;
  41.    and the THEM_PIECE bit is set iff the board contains a move for the human.
  42.  
  43.    So a return value of 0 means that the board represents the end of the game.
  44. */
  45. unsigned char
  46. who_can_move(struct board_struct *board_ptr)
  47. {
  48.    int aff_list[MAX_AFFECTED_PIECES];
  49.  
  50.    return (
  51.          (find_move(board_ptr, 0, US_PIECE, aff_list) ? US_PIECE : 0)
  52.       |
  53.          (find_move(board_ptr, 0, THEM_PIECE, aff_list) ? THEM_PIECE : 0)
  54.    );
  55. }
  56.